package vaccine.appointment.system.common.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import vaccine.appointment.system.common.constants.Constants;

@Configuration
public class MQConfig {
    /**
     * 声明队列
     */
    @Bean("noticeQueue")
    public Queue noticeQueue() {
        return QueueBuilder.durable(Constants.NOTICE_QUEUE).build();
    }

    /**
     * 声明交换机 (使用延时交换机)
     */
    @Bean("noticeExchange")
    public Exchange noticeExchange() {
        return ExchangeBuilder.directExchange(Constants.NOTICE_EXCHANGE).delayed().build();
    }

    /**
     * 绑定交换机和队列
     */
    @Bean("noticeBinding")
    public Binding noticeBinding(@Qualifier("noticeExchange") Exchange exchange, @Qualifier("noticeQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(Constants.NOTICE_KEY).noargs();
    }
}
